package com.yfbao.horizon.schedule.tk.service;

import com.github.houbb.sensitive.word.bs.SensitiveWordBs;
import com.github.houbb.sensitive.word.support.deny.WordDenys;
import com.github.houbb.sensitive.word.support.ignore.SensitiveWordCharIgnores;
import com.yfbao.horizon.schedule.tk.handler.DefaultWordDeny;
import com.yfbao.horizon.schedule.tk.handler.DefaultWordTag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
public class SensitiverService {

    private SensitiveWordBs wordBs;

    @Autowired
    private SensitiveWordBs sensitiveWordBs;

    public SensitiverService(){
        this.wordBs = SensitiveWordBs.newInstance()
                .ignoreCase(true)
                .ignoreWidth(true)
                .ignoreNumStyle(true)
                .ignoreChineseStyle(true)
                .ignoreEnglishStyle(true)
                .ignoreRepeat(false)
                .enableNumCheck(false)
                .enableEmailCheck(false)
                .enableUrlCheck(false)
                .enableWordCheck(true)
                .numCheckLen(8)
                .wordTag(new DefaultWordTag())
//                .wordDeny(new DefaultWordDeny())
                .charIgnore(SensitiveWordCharIgnores.defaults())
//                .wordReplace(new DefaultWordReplace())
                .init();
    }

    public List<String> checkSensitive(String text){
        wordBs.wordDeny(WordDenys.chains(new DefaultWordDeny())).init();
        List<String> all = wordBs.findAll(text);
        return all;
    }

    public List<String> checkSensitive2(String text){
        sensitiveWordBs.wordDeny(WordDenys.chains(new DefaultWordDeny())).init();
        List<String> all = sensitiveWordBs.findAll(text);
        return all;
    }

    public String replaceSensitive(){
        return null;
    }
}
